package com.jinsi.service.impl;

import com.jinsi.mapper.ScPrintMapper;
import com.jinsi.pojo.ScPrint;
import com.jinsi.pojo.ScPrintRecord;
import com.jinsi.pojo.ScStudent;
import com.jinsi.service.ScPrintService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class ScPrintServiceImpl implements ScPrintService {

    @Autowired
    private ScPrintMapper mapper;


    @Override
    public List<ScPrintRecord> getPrintRecord() {
        List<ScPrintRecord> list = mapper.getPrintRecord();
        return list;
    }

    @Override
    public List<ScPrintRecord> getPrintRecordByStuName(String studentName) {
        List<ScPrintRecord> list = mapper.getPrintRecordByStuName(studentName);
        return list;
    }


    @Override
    public void addPrintRecord(ScPrintRecord record) throws Exception {
        int num = mapper.addPrintRecord(record);
        if (num == 0){
            throw new Exception();
        }
    }

    @Override
    public ScStudent getStudent(String studentId) {
        ScStudent student = mapper.getStudent(studentId);
        return student;
    }

    @Override
    public List<Map<String,Object>> getPrint(String documentId) {
        List<Map<String,Object>> prints = mapper.getPrint(documentId);
        return prints;
    }

    @Override
    public List<Map<String, Object>> getPrintById(int id) {
        List<Integer> idlist = getIdlist(id);
        System.out.println(idlist);
        List<Map<String, Object>> printById = mapper.getPrintById(id, idlist);
        return printById;
    }

    @Override
    public List<Integer> getIdlist(int id) {
        String idlist = mapper.getIdlist(id);
        String replace = idlist.replace("[", "");
        String replace1 = replace.replace("]", "");
        String[] split = replace1.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i = 0 ; i < split.length ; i++){
            list.add(new Integer(split[i]));
        }
        return list;
    }




}
